/**
 * This file is part of the dspace-poltman project http://www.poltman.com.
 *
 * This is free software; you can redistribute it and/or modify it under
 * the terms of DuraSpace DSpace license detailed in the LICENSE and NOTICE 
 * files at the root of the source tree and available online at
 * http://www.dspace.org/license/
 * 
 */
package com.poltman.dscentral.epeople;

import org.apache.log4j.Logger;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zkplus.spring.SpringUtil;
import org.zkoss.zul.Combobox;

import com.poltman.dscentral.core.CoreSessionData;
import com.poltman.dscentral.db.entity.pm.LanguagesEntity;
import com.poltman.dscentral.db.exceptions.RepositoryAccessException;
import com.poltman.dscentral.db.exceptions.RepositoryException;
import com.poltman.dscentral.db.service.pm.LanguagesService;
import com.poltman.dscentral.login.SelectLanguage;

/**
 * 
 * @author z.ciok@poltman.com
 * @version $Revision: 1548 $
 *
 */
public class AddEPeopleSelectLanguage {

	private static Logger log = Logger.getLogger(AddEPeopleSelectLanguage.class);
	
	@Wire("combobox")
	Combobox combobox;
	
	@Listen("onSelect = combobox#languageTxb")
	public void selectLanguage() {
		String selectedLanguageName = combobox.getSelectedItem().getValue();
		LanguagesService  languagesService = (LanguagesService) SpringUtil.getBean("languagesService");
		LanguagesEntity language = null;
		try {
			language = languagesService.findByName(selectedLanguageName);
		} catch (RepositoryAccessException rae) {
			log.error("SelectLanguage Error: ", rae);
		} catch (RepositoryException re) {
			log.error("SelectLanguage Error: ", re);
		}
		CoreSessionData coreSessionData = (CoreSessionData) SpringUtil.getBean("coreSessionData");
		coreSessionData.setSelectedLanguageCode(language.getCode());
		log.info("Login select language = " + selectedLanguageName + "; code = " + coreSessionData.getSelectedLanguageCode());
	}	
}
